﻿using System;
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using System.ComponentModel.DataAnnotations;
using HengTong.Model;
using HengTong.Model.Db;
using HengTong.Model.Db.Hr;
using TiaoTaoHelper.Wtm.Models;


namespace HengTong.ViewModel.Hr.SysHrStaffPoolVms
{
    public partial class SysHrStaffPoolListVm : BasePagedListVM<SysHrStaffPoolView, SysHrStaffPoolSearcher>
    {
        protected override IEnumerable<IGridColumn<SysHrStaffPoolView>> InitGridHeader()
        {
            return new List<GridColumn<SysHrStaffPoolView>>
            {
                this.MakeGridHeader(x => x.HrStatus),
                this.MakeGridHeader(x => x.BillNo),
                this.MakeGridHeader(x => x.StaffNeedEntryName),

                this.MakeGridHeader(x => x.HireNumber),
                this.MakeGridHeader(x => x.ApplyReason),
                this.MakeGridHeader(x => x.ExpectedDate),
                this.MakeGridHeader(x => x.JobRequirement),
                this.MakeGridHeader(x => x.EducationRequirement),
                this.MakeGridHeader(x => x.MajorRequirement),
                this.MakeGridHeader(x => x.GenderRequirement),
                this.MakeGridHeader(x => x.AgeRequirement),
                this.MakeGridHeader(x => x.OtherRequirement),
                this.MakeGridHeader(x => x.GroupName),
                this.MakeGridHeader(x => x.OrgName),
                this.MakeGridHeader(x => x.JobPositionName),
                // 主表
                this.MakeGridHeader(x => x.BillCode),
                this.MakeGridHeader(x => x.BillStatus),
                this.MakeGridHeader(x => x.Remark),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysHrStaffPoolView> GetSearchQuery()
        {
            var query = DC.Set<SysHrStaffPool>()
                .CheckEqual(Searcher.HrStatus, x => x.HrStatus)
                .CheckContain(Searcher.BillNo, x => x.BillNo)
                .CheckContain(Searcher.GroupName, x => x.StaffNeedEntry.Group.GroupName)
                .CheckContain(Searcher.JobPositionName, x => x.StaffNeedEntry.JobPosition.Name)
                .CheckEqual(Searcher.GroupId, x => x.StaffNeedEntry.GroupId)
                .CheckEqual(Searcher.OrgId, x => x.StaffNeedEntry.OrgId)
                .CheckContain(Searcher.OrgName, x => x.StaffNeedEntry.Org.Name)
                .Select(x => new SysHrStaffPoolView
                {
                    ID = x.ID,
                    HrStatus = x.HrStatus,
                    BillNo = x.BillNo,
                    // 用人需求明细
                    HireNumber = x.StaffNeedEntry.HireNumber,
                    ApplyReason = x.StaffNeedEntry.ApplyReason,
                    ExpectedDate = x.StaffNeedEntry.ExpectedDate,
                    JobRequirement = x.StaffNeedEntry.JobRequirement,
                    EducationRequirement = x.StaffNeedEntry.EducationRequirement,
                    MajorRequirement = x.StaffNeedEntry.MajorRequirement,
                    GenderRequirement = x.StaffNeedEntry.GenderRequirement,
                    AgeRequirement = x.StaffNeedEntry.AgeRequirement,
                    OtherRequirement = x.StaffNeedEntry.OtherRequirement,
                    GroupName = x.StaffNeedEntry.Group.GroupName,
                    OrgName = x.StaffNeedEntry.Org.Name,
                    JobPositionName = x.StaffNeedEntry.JobPosition.Name,
                    // 主表
                    BillCode = x.StaffNeedEntry.HrStaffNeed.BillCode,
                    BillStatus = x.StaffNeedEntry.HrStaffNeed.BillStatus,
                    Remark = x.StaffNeedEntry.HrStaffNeed.Remark,
                    CreateTime = x.CreateTime // 添加CreateTime属性
                })
                .OrderByDescending(x => x.CreateTime);
            return query;
        }
    }

    public class SysHrStaffPoolView : SysHrStaffPool
    {
        [Display(Name = "岗位要求")] public String StaffNeedEntryName { get; set; }
        [Display(Name = "招聘人数")] public int HireNumber { get; set; }
        [Display(Name = "申请原因")] public string ApplyReason { get; set; }
        [Display(Name = "到岗时间")] public DateTime? ExpectedDate { get; set; }
        [Display(Name = "岗位要求")] public string JobRequirement { get; set; }
        [Display(Name = "学历要求")] public EducationLevel? EducationRequirement { get; set; }
        [Display(Name = "专业要求")] public string MajorRequirement { get; set; }
        [Display(Name = "性别要求")] public Gender? GenderRequirement { get; set; }
        [Display(Name = "年龄要求")] public string AgeRequirement { get; set; }
        [Display(Name = "其他要求")] public string OtherRequirement { get; set; }
        [Display(Name = "部门名称")] public String GroupName { get; set; }

        [Display(Name = "公司名称")] public String OrgName { get; set; }
        [Display(Name = "岗位名称")] public String JobPositionName { get; set; }

        // 主表
        [Display(Name = "单据编号")] public String BillCode { get; set; }
        [Display(Name = "单据状态")] public BillStatus? BillStatus { get; set; }
        [Display(Name = "备注")] public string Remark { get; set; }
    }
}